package org.jclip.browser;

import java.security.Permission;
import java.util.ArrayList;


public class ClassLoaderManager extends SecurityManager {

	public ClassLoaderManager()
	{
		super();
	}
	
	
	public void checkPermission(Permission p){
		
	}

	public void checkRead(String f) 
	{
		boolean exists = false;
		boolean exists2 = false;
		Class<?>[] cls = getClassContext();
		ArrayList<String> nms = new ArrayList<String>();
		ArrayList<String> pkgs = new ArrayList<String>();
		for(int i=0; i<cls.length; i++){
			nms.add(cls[i].getName());
			pkgs.add(nms.get(i));
			String pkg = pkgs.get(i);
				
			if(pkg.startsWith("java.io.FileInputStream")){
				exists=true;
			}
			
			if(!(pkg.startsWith("java"))&&(!(pkg.startsWith("sun")))&&(!(pkg.startsWith("com")))&&(!(pkg.startsWith("org.jclip.browser")))){

				exists2=true;
			}
		}
		
		if(exists&&exists2){
			throw new SecurityException("read access denied");
		} 
	}
	
	public void checkWrite(String f)
	{
		boolean exists = false;
		boolean exists2 = false;
		Class<?>[] cls = getClassContext();
		ArrayList<String> nms = new ArrayList<String>();
		ArrayList<String> pkgs = new ArrayList<String>();
		for(int i=0; i<cls.length; i++){
			nms.add(cls[i].getName());
			pkgs.add(nms.get(i));
			String pkg = pkgs.get(i);
				
			if(pkg.startsWith("java.io.FileOutputStream")){
				exists=true;
			}
			
			if(!(pkg.startsWith("java"))&&(!(pkg.startsWith("sun")))&&(!(pkg.startsWith("com")))&&(!(pkg.startsWith("org.jclip.browser")))){

				exists2=true;
			}
			
			
		}
		
		
		if(exists&&exists2){
			throw new SecurityException("write access denied");
		} 
	}
}